﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Display.MarketUI.*;
    import flash.text.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import com.zynga.skelly.util.*;

    public class MysteryCrateDialogView extends GenericDialogView {

        private var m_animatedSpinner:AutoAnimatedBitmap;
        private var m_animateRelative:String;
        private var m_iconPane:JPanel;
        private var m_winningPane:JPanel;
        private var m_textComponent:Component;
        private var m_largeIconPane:JPanel;
        private var m_buttonPane:JPanel;
        private var m_buttonStrut:JPanel;
        private var m_textContainer:Component;

        public function MysteryCrateDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:String="", _arg7:int=0, _arg8:String="", _arg9:Function=null, _arg10:String="", _arg11:Boolean=true){
            super(_arg1, _arg2, _arg3, _arg4, _arg5, _arg6, _arg7, _arg8, _arg9, _arg10);
        }
        override protected function makeCenterPanel():void{
            super.makeCenterPanel();
            this.m_buttonPane.visible = false;
            this.m_buttonStrut = ASwingHelper.verticalStrut(35);
            interiorHolder.append(this.m_buttonStrut);
            ASwingHelper.prepare(this.parent);
        }
        override protected function createTextArea():JPanel{
            var _local1:JPanel;
            var _local2:Number;
            _local1 = ASwingHelper.makeFlowJPanel(SoftBoxLayout.CENTER, 0);
            this.m_largeIconPane = this.iconLoaderPane("assets/dialogs/citysam_celebrate.png");
            var _local3:Class = Catalog.assetDict["card_available_unselected"];
            var _local4:DisplayObject = (new (_local3)() as DisplayObject);
            var _local5:Number = 10;
            m_messagePaddingLeft = 8;
            m_messagePaddingRight = 20;
            if (((!((m_icon == null))) && (!((m_icon == ""))))){
                _local2 = setMessageTextWidth((((m_iconPos == ICON_POS_LEFT)) || ((m_iconPos == ICON_POS_RIGHT))));
                this.m_animateRelative = "assets/dialogs/mystery_crate_anim70x74.png";
                this.m_iconPane = this.animatedPane(this.m_animateRelative, _local4);
            };
            this.m_largeIconPane.visible = false;
            this.m_textContainer = this.createTextComponent(_local2);
            var _local6:JPanel = createTextAreaInnerPane(this.m_textContainer);
            var _local7:JPanel = this.m_iconPane;
            var _local8:JPanel = _local6;
            _local1.append(ASwingHelper.horizontalStrut(m_messagePaddingLeft));
            _local1.append(this.m_largeIconPane);
            _local1.append(ASwingHelper.horizontalStrut(_local5));
            if ((((m_iconPos == ICON_POS_LEFT)) || ((m_iconPos == ICON_POS_RIGHT)))){
                if (_local7){
                    _local1.append(_local7);
                };
                _local1.append(ASwingHelper.horizontalStrut(m_messagePaddingRight));
                if (_local8){
                    _local1.append(_local8);
                };
            };
            _local1.append(ASwingHelper.horizontalStrut(m_messagePaddingRight));
            var _local9:int = this.m_textContainer.getHeight();
            return (_local1);
        }
        public function showWinnings(_arg1:Item, _arg2:Boolean):void{
            var _local6:TextFormat;
            var _local3:Class = Catalog.assetDict["card_available_unselected"];
            var _local4:DisplayObject = (new (_local3)() as DisplayObject);
            var _local5:int = textArea.getIndex(this.m_iconPane);
            var _local7:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            ASwingHelper.setSizedBackground(_local7, _local4);
            this.m_winningPane = this.iconLoaderPane(_arg1.iconRelative, _local4);
            _local7.append(this.m_winningPane);
            textArea.remove(this.m_iconPane);
            textArea.insert(_local5, _local7);
            _local6 = TextField(AssetPane(this.m_textComponent).getAsset()).getTextFormat();
            var _local8:String = (_arg2) ? ZLoc.t("Dialogs", "Mystery_Crate_message", {itemName:_arg1.localizedName}) : ZLoc.t("Dialogs", "Mystery_Crate_gateFail", {itemName:_arg1.localizedName});
            TextField(AssetPane(this.m_textComponent).getAsset()).text = _local8;
            TextField(AssetPane(this.m_textComponent).getAsset()).setTextFormat(_local6);
            var _local9:Number = 95;
            ASwingHelper.prepare(this.m_textContainer);
            this.m_textContainer.setPreferredHeight(_local9);
            this.m_textComponent.setPreferredHeight(_local9);
            ASwingHelper.prepare(this.m_textContainer);
            ASwingHelper.prepare(textArea);
            this.m_largeIconPane.visible = true;
            this.m_buttonPane.visible = _arg2;
            this.m_buttonStrut.visible = !(_arg2);
            ASwingHelper.prepare(this.parent);
        }
        protected function animatedPane(_arg1:String, _arg2:DisplayObject=null):JPanel{
            var iconPane:* = null;
            var iconInnerPane:* = null;
            var iconString:* = null;
            var iconLoader:* = null;
            var offy:* = NaN;
            var offx:* = NaN;
            var iconRelativePath:* = _arg1;
            var bkgAsset = _arg2;
            iconPane = new AssetPane();
            iconInnerPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            if (!Catalog.assetDict[iconRelativePath]){
                iconString = Global.getAssetURL(iconRelativePath);
                iconLoader = LoadingManager.load(iconString, Curry.curry(function (_arg1:JPanel, _arg2:Event):void{
                    var _local3:*;
                    var _local4:*;
                    var _local5:*;
                    if ((iconLoader.content is Bitmap)){
                        _local3 = (iconLoader.content as Bitmap);
                        m_animatedSpinner = new AutoAnimatedBitmap(_local3.bitmapData, 2, 70, 74, 12);
                        Catalog.assetDict[iconRelativePath] = _local3;
                    };
                    iconPane.setAsset(m_animatedSpinner);
                    ASwingHelper.prepare(_arg1);
                    if (bkgAsset){
                        _local4 = (Math.abs((bkgAsset.height - iconLoader.content.height)) / 2);
                        _local5 = (Math.abs((bkgAsset.width - iconLoader.content.width)) / 2);
                        ASwingHelper.setEasyBorder(iconInnerPane, _local4, _local5, _local4, _local5);
                    };
                    Catalog.assetDict[iconRelativePath] = iconLoader.content;
                    _arg1.dispatchEvent(new UIEvent(UIEvent.REFRESH_DIALOG, "iconLoaded", true));
                }, iconInnerPane));
            } else {
                this.m_animatedSpinner = new AutoAnimatedBitmap(Catalog.assetDict[iconRelativePath].bitmapData, 2, 70, 74, 12);
                iconPane.setAsset(this.m_animatedSpinner);
                ASwingHelper.prepare(this.m_animatedSpinner);
                if (bkgAsset){
                    offy = (Math.abs((bkgAsset.height - Catalog.assetDict[iconRelativePath].height)) / 2);
                    offx = (Math.abs((bkgAsset.width - Catalog.assetDict[iconRelativePath].width)) / 2);
                    ASwingHelper.setEasyBorder(iconInnerPane, offy, offx, offy, offx);
                };
            };
            iconInnerPane.append(iconPane);
            return (iconInnerPane);
        }
        protected function iconLoaderPane(_arg1:String, _arg2:DisplayObject=null):JPanel{
            var iconPane:* = null;
            var iconInnerPane:* = null;
            var iconLoader:* = null;
            var iconRelativePath:* = _arg1;
            var bkgAsset = _arg2;
            iconPane = new AssetPane();
            var iconString:* = Global.getAssetURL(iconRelativePath);
            iconInnerPane = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            iconLoader = LoadingManager.load(iconString, Curry.curry(function (_arg1:JPanel, _arg2:Event):void{
                var _local3:*;
                var _local4:*;
                iconPane.setAsset(iconLoader.content);
                ASwingHelper.prepare(_arg1);
                if (bkgAsset){
                    _local3 = (Math.abs((bkgAsset.height - iconLoader.content.height)) / 2);
                    _local4 = (Math.abs((bkgAsset.width - iconLoader.content.width)) / 2);
                    ASwingHelper.setEasyBorder(iconInnerPane, _local3, _local4, _local3, _local4);
                };
                _arg1.dispatchEvent(new UIEvent(UIEvent.REFRESH_DIALOG, "iconLoaded", true));
            }, iconInnerPane));
            iconInnerPane.append(iconPane);
            return (iconInnerPane);
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, AsWingConstants.CENTER));
            var _local2:JPanel = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            if (m_type != TYPE_NOBUTTONS){
                _local1.append(_local2);
            };
            _local1.append(ASwingHelper.verticalStrut(20));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(3));
            if (((!((m_type == TYPE_MODAL))) && (!((m_type == TYPE_NOBUTTONS))))){
                this.m_buttonPane = createButtonPanel();
                _local1.append(this.m_buttonPane);
            };
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTextComponent(_arg1:Number):Component{
            var _local2:Component;
            var _local4:Number;
            var _local5:Container;
            m_align = TextFormatAlign.LEFT;
            this.m_textComponent = ASwingHelper.makeMultilineText(m_message, _arg1, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, m_align, 18, EmbeddedArt.blueTextColor);
            var _local3:Number = 75;
            if (this.m_textComponent.getHeight() < _local3){
                _local4 = ((_local3 - this.m_textComponent.getHeight()) / 2);
                _local5 = ASwingHelper.makeSoftBoxJPanelVertical();
                _local5.append(ASwingHelper.verticalStrut(_local4));
                _local5.append(this.m_textComponent);
                _local5.append(ASwingHelper.verticalStrut(_local4));
                _local2 = _local5;
            } else {
                _local2 = this.m_textComponent;
            };
            return (_local2);
        }

    }
}//package Display.DialogUI 
